/**
 * 将对象转为url参数params
 * @export
 * @param {*} json
 * @param {string} [slice="&"]
 * @returns
 */
export function objectObjToParams(json, slice = "&") {
  return Object.keys(json)
    .reduce((acc, item) => {
      return String(acc) + item + "=" + json[item] + slice;
    }, "")
    .slice(0, -1);
}

/**
 * 深拷贝
 * @export
 * @param {*} target
 * @param {*} [map=new Map()]
 * @returns
 */
export function deepClone(target, map = new Map()) {
  if (typeof target === "object") {
    let cloneTarget = Array.isArray(target) ? [] : {}
    if (map.get(target)) {
      return target
    }
    map.set(target, cloneTarget)
    for (const key in target) {
      cloneTarget[key] = deepClone(target[key], map)
    }
    return cloneTarget
  } else {
    return target
  }
}

